package com.github.zxhtom.excel.expose;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.github.zxhtom.excel.Excel;
import com.github.zxhtom.excel.model.Student;

import java.util.List;

/**
 * @package com.github.zxhtom.excel.expose
 * @Class EasyExcel
 * @Description TODO
 * @Author zhangxinhua
 * @Date 19-11-6 下午2:07
 */
public class EasyExcelTools<T> implements Excel<T> {

    @Override
    public void readData() {

    }

    @Override
    public void export(List<T> ts) {
        String fileName = EasyExcelTools.class.getResource("/").getPath() + "student" + System.currentTimeMillis() + ".xlsx";
        ExcelWriterBuilder excelWriterBuilder = EasyExcel.write(fileName, Student.class);
        //excelWriterBuilder.registerConverter(new SexConverter()).registerWriteHandler(new AgeRowHandler()).registerWriteHandler(new SexCellWriteHandler());
        ExcelWriter excelWriter = excelWriterBuilder.build();
        WriteSheet writeSheet = EasyExcel.writerSheet("中化安元").build();
        try {
            excelWriter.write(ts, writeSheet);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            excelWriter.finish();
        }
    }

}
